import { getDetailsByIdApi } from "@/api/client/documentManagement/waybillManagement";
import { reactive, ref } from "vue";
import { formItemColumn } from "../data";
export default function InitHook() {
  const formState = ref<Partial<ClientWaybillManagement.WaybillDetails>>({
    preOrderShipmentBoxVolume: [],
    bizPreOrderShipmentFileResDtoList: []
  });
  const loading = ref<boolean>(false);
  const dialogOpts = reactive<Base.DialogOpts>({
    title: "修改送货仓库",
    width: "720px",
    type: 1,
    passData: {},
    component: "",
    visible: false
  });
  const drawerOpts = reactive<Base.DrawerOpts>({
    title: "",
    width: "520px",
    component: "",
    visible: false,
    type: 1,
    passData: {}
  });
  const init = async (id: string) => {
    loading.value = true;
    return getDetailsByIdApi(id)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          formState.value = data;
        }
      })
      .finally(() => {
        loading.value = false;
      });
  };

  const detailsActiveKey = ref<string>("1"); //详情tab页

  const formItemColumnMap = ref<Array<{ name: string; label: string }>>(formItemColumn);

  return {
    formState,
    dialogOpts,
    init,
    loading,
    drawerOpts,
    detailsActiveKey,
    formItemColumnMap
  };
}
